/*
 * Copyright © 2009 Perseus Project - Tufts University <http://www.perseus.tufts.edu>
 *
 * This file is part of UniCollatorPerseus.
 *
 * OcroPerseus is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * OcroPerseus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with OcroPerseus.  If not, see <http://www.gnu.org/licenses/>.
 */

package eu.himeros.ocr.image;

import eu.himeros.util.IoManager;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.util.Vector;

/**
 * Combine training and text.
 * Main class.<br/>
 * uses: IoManager<br/>
 * Pipe with GlyphIdentifier: GlyphIdentifier --> out.log --> CombineTrainingAndText
 *
 * @author federico
 */

@Deprecated
public class CombineTrainingAndText {
    BufferedReader trainBr=null;
    BufferedReader textBr=null;
    BufferedWriter bw=null;
    
    /**
     *
     */
    public CombineTrainingAndText(){}

    /**
     *
     * @param args
     */
    public void init(String[] args){
        try{
            trainBr=IoManager.getReader(args[0]);
            textBr=IoManager.getReader(args[1]);
            bw=IoManager.getWriter(args[2]);
            Vector<String> greekChar=new Vector<String>(1000);
            Vector<String> coords=new Vector<String>(1000);
            String line=null;
            String gStr=null;
            int cnt=0;
            while((line=textBr.readLine())!=null){
                for(int i=0;i<line.length();i++){
                    gStr=""+line.charAt(i);
                    if(!gStr.equals(" ")){
                        greekChar.add(gStr);
                        cnt++;
                    }
                }
                System.out.println("read-chars: "+cnt);
                cnt=0;
            }
            while((line=trainBr.readLine())!=null){
                if(line.length()>0){
                    if(line.startsWith("@")){
                        coords.add(line.substring(2));
                        cnt++;
                    }else if(line.equals("$")){
                        System.out.println("read-coords: "+cnt);
                        cnt=0;
                    }
                }
            }
            for(int i=0;i<greekChar.size();i++){
                bw.write(greekChar.elementAt(i)+" "+coords.elementAt(i));bw.newLine();
            }
            bw.flush();bw.close();
        }catch(Exception e){e.printStackTrace();}        
    }

    /**
     *
     * @param args
     */
    public static void main(String[] args){
        if(args==null||args.length==0){
            System.out.println("It combines output of GlyphIdentifier to the ground truth (correct transcription of a text)");
            System.out.println("OBSOLETE");
            System.out.println("Usage: java eu.himeros.ocrtrainer.CombineTrainingAndText  <glyphFile> <textFile> <outputFile>");
            System.out.println("<glyphFile> output of GlyphIdentifier");
            System.out.println("<textFile> ground truth file");
            System.out.println("<outputFile> result");
            System.exit(1);
        }
        CombineTrainingAndText ctat=new CombineTrainingAndText();
        ctat.init(args);
    }

}
